package com.study.springcloud.controller;

import com.study.springcloud.consts.Constant;
import com.study.springcloud.pojo.Goods;
import com.study.springcloud.response.ResultObject;
import com.study.springcloud.serivce.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author Chen Jie
 * @Date 2022/3/5 14:02
 * @Version 1.0
 */
@RefreshScope
@RestController
public class GoodsController {
    private GoodsService goodsService;
    @Value("${test.refresh.variable}")
    private String testRefreshVariable;

    @Autowired
    public GoodsController(GoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @GetMapping("/service/goods")
    public ResultObject goods() throws InterruptedException {
        List<Goods> goodsList = goodsService.getAllGoods();

//        TimeUnit.SECONDS.sleep(2);

//        if(1 == 1) {
//            throw new RuntimeException("service provider GG了...");
//        }

        return new ResultObject(Constant.OK, "查询成功", goodsList);
    }

    @RequestMapping("/getVariable")
    public String getVariable() {
        return testRefreshVariable;
    }
}
